package org.nf.trading.controller.admin.product;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nf.trading.controller.BaseController;
import org.nf.trading.dto.ProductCommentDTO;
import org.nf.trading.entity.Product;
import org.nf.trading.service.app.product.ProductService;
import org.nf.trading.vo.ResultVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
@RequiredArgsConstructor
@Slf4j
public class ProductManagementController extends BaseController {
    private final ProductService productService;

    //修改商品的状态

    /**
     * 通过商品状态查询全部商品
     * @param status
     * @return
     */
    @GetMapping("/productStatus/{status}")
    public ResultVO getProductByStatus(@PathVariable("status") Integer status){
        List<Product> productList = productService.getProductByStatus(status);
        return success(productList);
    }

    /**
     * 通过商品id查询，包括用户信息和评价
     * @param productId
     * @return
     */
    @GetMapping("/productsId/{productId}")
    public ResultVO getProductById(@PathVariable("productId") Integer productId){
        ProductCommentDTO product = productService.getProductById(productId);
        System.out.println("product = " + product);
        return success(product);
    }

    /**
     * 通过商品分类详细id查询全部商品
     * @param productTypeDetailId
     * @return
     */
    @GetMapping("/productTypeDetailId/{productTypeDetailId}")
    public ResultVO getProductByTypeDetailId(@PathVariable("productTypeDetailId") Integer productTypeDetailId){
        List<Product> productList = productService.getProductByTypeDetailId(productTypeDetailId);
        return success(productList);
    }
}
